package com.yingxin.yxerp.service;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;

/**
 * @author fanchao
 */
@Configuration
public class DataSourceConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dataSource() {
        return new DruidDataSource();
    }

//    @Bean("master")
//    @Primary
//    @ConfigurationProperties(prefix = "spring.datasource.master")
//    public DataSource master() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean("slave")
//    @ConfigurationProperties(prefix = "spring.datasource.slave")
//    public DataSource slave() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean
//    public DynamicDataSource dataSource(DataSource master, DataSource slave) {
//        Map<Object, Object> targetDataSources = new HashMap<>();
//        targetDataSources.put("master",master);
//        targetDataSources.put("slave", slave);
//        return new DynamicDataSource(master, targetDataSources);
//    }


    /*
    @Primary
    @Bean("dataSource")
    public DataSourceProxy dataSource(DataSource druidDataSource) {
        return new DataSourceProxy(druidDataSource);
    }
*/
}
